﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Cfg;
using NHibernate;
using FluentNHibernate.Cfg.Db;
using NHibernate.Cfg;

namespace Magnet.Models.NHFluent.Start
{
    internal class NHContext
    {
        public static ISessionFactory CreateSessionFactory()
        {
            return Fluently.Configure()
                .Database(
                MsSqlConfiguration.MsSql2005
                  .ConnectionString(c => c
                    .Server("princepc")
                    .Database("NHibernate")
                    .Username("beta")
                    .Password("beta"))
                )
                .Mappings(m =>
                  m.FluentMappings.AddFromAssemblyOf<NHContext>())
                .BuildSessionFactory();

        }

        public static void BuildSchema(Configuration config)
        {
            //// delete the existing db on each run
            //if (File.Exists(DbFile))
            //    File.Delete(DbFile);
 
            //// this NHibernate tool takes a configuration (with mapping info in)
            //// and exports a database schema from it
            //new SchemaExport(config)
            //    .Create(false, true);
        }

    }
}
